<template>
    <div id="AsnDetailList">
        <v-tableTitle :btnConfig="btnConfig" :tableSelectData="selectData" @backList="backList"
                      @del="del" @newCreate="newCreate"></v-tableTitle>

        <div class="detail">
            <component :data="{detailData,argument}" :is="currentComponent"></component>
        </div>
    </div>

</template>

<script>
    import tableTitle from "commons/TableTitle";
    import navMenu from "commons/NavMenu";
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        name: "AsnDetailList",
        mixins: [baseMixin],
        data() {
            return {
                newFlag: false,
                argument: {},
                detailsFlag: false,
                detailData: {},
                selectData: [],
                detailNav: "1",
                componentConfig: [
                    {
                        name: "Table",
                        label: this.$t('config.tableDetail'),
                        component: () => import('./page/Table.vue')
                    },
                    {
                        name: "Detail",
                        label: this.$t('bill.detail'),
                        component: () => import('./page/Detail.vue')
                    },
                ],
            }
        },
        computed: {
            btnConfig() {
                if (this.newFlag) {
                    return []
                } else if (this.detailNav == "1") {
                    return [
                        {label: this.$t('common.create'), certigier: this.$parent.newStatus||!this.btnPermNameList.includes('WM03070205'), invalid: "newCreate"},
                        {label: this.$t('common.delete'), certigier: this.$parent.deleteStatus||!this.btnPermNameList.includes('WM03070206'), disabled: true, invalid: "del"},
                    ]
                } else if (this.detailNav == "2") {
                    return [
                        {label: this.$t('outbound.backList'),certigier: !this.btnPermNameList.includes('WM03070207'), invalid: "backList"},
                    ]
                }
                return []
            },
            currentComponent() {
                return this.componentConfig[this.detailNav - 1].component;
            }
        },
        methods: {
            //删除数据
            async del(data) {
                try {
                    let res = await this.$api.post(`/deleteallocatestrategydetail`, data);
                    
                        this.$message.success(res.returnMgr);
                        this.$children[1].getTableData(1);
                        this.$children[1].$refs.table.delSelectData(data);
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },

            //返回试图
            backList() {
                this.detailsFlag = false;
                this.detailNav = '1';
            },
            //新建
            async newCreate() {
                this.detailData = {
                    stepnumber: "10",
                    uom: "",
                    descr: " ",
                    locationtypeoverride: " ",
                    locallocationsort: "1",
                    locationtypeoverridestripe: " ",
                    locationcategoryoverride: " ",
                    pickcode: " ",
                    groupuompicks: "0",
                    allowoverallocations: "0",
                    allocatestrategylinenumber: " ",
                    whseid: this.$store.state.wms,
                    allocatestrategykey: this.argument.allocatestrategykey
                };
                try {
                    let res = await this.$api.post(`/queryallocatedetailmaxstepnumber`, this.detailData);
                    
                        this.detailData.stepnumber = String((this.detailData.stepnumber - 0) + (res.data.token - 0));
                        this.detailsFlag = true;
                        this.detailNav = '2';
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },

            async enterDetails(data) {
                try {
                    let res = await this.$api.get(`/querybyallocatestrategydetail12/${data.serialkey}`);
                    
                        this.detailData = res.bean;
                        this.detailNav = '2';
                    
                } catch (e) {
                    this.$message.error(e);
                }

            }

        },
        mounted() {
            this.newFlag = this.$store.state.newFlag;
            if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                this.argument = data.routeData;
                this.detailData = data.detailList;
                this.detailNav = data.detailListNav;
                this.detailsFlag = data.detailListFlag
            } else if (this.newFlag) {
                this.newFlag = true;
                this.detailData = {
                    stepnumber: "10",
                    uom: "",
                    descr: " ",
                    locationtypeoverride: " ",
                    locallocationsort: "1",
                    locationtypeoverridestripe: " ",
                    locationcategoryoverride: " ",
                    pickcode: " ",
                    groupuompicks: "0",
                    allowoverallocations: "0",
                    allocatestrategylinenumber: "1",
                    whseid: this.$store.state.wms,
                };
                this.detailNav = "2";
            } else {
                this.argument = this.$store.state.routeData;
            }
        },
        components: {
            "v-tableTitle": tableTitle,
            "v-navMenu": navMenu,
        },
        watch: {
            selectData(data) {
                if (this.$parent.permissionStatus) {
                    if (data.length > 0) {
                        this.$parent.deleteStatus = false;
                    } else {
                        this.$parent.deleteStatus = true;
                    }
                }
            }
        }
    }
</script>

<style>

</style>
